<template>
	<view class="container">
		
		<my-address></my-address>
		<view class="cart-title">
		  <!-- 左侧的图标 -->
		  <uni-icons type="shop" size="18"></uni-icons>
		  <!-- 描述文本 -->
		  <text class="cart-title-text">购物车</text>
		</view>
	
		<!--  侧滑 -->
		<uni-swipe-action v-if="cart.length != 0">
			<view class="cart-box">
				<block class="cart-list" v-for="(goods, i) in cart" :key="i">
					<!-- radio和num-change 都属于自定义指定 -->
					<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
						<my-goods :item="goods" @radio-change="radioChangeHandler" @num-change="numberChangeHandler"></my-goods>
					</uni-swipe-action-item>
				</block>
			</view>
		</uni-swipe-action>
		
		<view class="empty-cart" v-else>
		    <image src="../../static/logo.png" class="empty-img"></image>
		    <text class="tip-text">空空如也~</text>
		</view>
		<my-settle v-if="cart.length != 0"></my-settle>
	</view>

</template>

<script>

import { mapState, mapMutations } from 'vuex' 
import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		data() {
			return {
				options:[
					{
						text: "删除",
						style: {
							backgroundColor: '#eb4450'
						}
					}
				]
			};
		},
		computed:{
			...mapState('m_cart', ['cart'])
		},
		methods:{
			...mapMutations('m_cart', ['updateGoodsState','updateGoodsNumber','removeGoodsById']),
			radioChangeHandler(e) {
				this.updateGoodsState(e)
				// console.log(e);
			},
			numberChangeHandler(e){
				// console.log(e);
				this.updateGoodsNumber(e)
			},
			swipeActionClickHandler(goods){
				console.log(goods);
				this.removeGoodsById(goods.goods_id)
			      this.$u.toast("删除成功")
			}
		},
		mixins: [badgeMix],
		watch:{
			
		}
		
	}
</script>

<style lang="scss">
	.container {
		.cart-title {
			padding: 25rpx;
			border-bottom: 1px solid #efefef;
			display: flex;
			align-items: center;
			.cart-title-text {
				margin-left: 5rpx;
			}
		}
		.empty-cart {
		  display: flex;
		  flex-direction: column;
		  align-items: center; //副轴
		  padding-top: 150px;
		
		  .empty-img {
		    width: 90px;
		    height: 90px;
		  }
		
		  .tip-text {
		    font-size: 12px;
		    color: gray;
		    margin-top: 15px;
		  }
		}
	}
	
</style>
